<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>驴妈妈统计系统</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.css" />
<link rel="stylesheet"
	href="${request.contextPath}/static/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery.gritter.min.css" />
<!-- text fonts -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace.min.css"
	class="ace-main-stylesheet" id="main-ace-style" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/stylesheets/daterangepicker.css">
<script src="${request.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
</head>
<body class="no-skin" style="background-color: #FFF;">
	<div class="page-content" style="padding: 2px 2px 0px;">
	 	<div class="tabbable">
			<div class="tab-content">
		 		<div id="manage" class="tab-pane active in">
		 		<!-- 筛选条件开始 -->
					<div class="row">
						<div class="col-sm-12">
							<div class="widget-box">
								<div class="widget-body" style="background-color: #EFF3F8;">
									<div class="widget-main">
										<form class="form-inline" id="searchForm" method="post"
										action="${request.contextPath}/backJobConfig/timerList">
										<input type="hidden" id="_csrf" name="${_csrf.parameterName}"
											value="${_csrf.token}" />
										<!-- 框架原因，所有post请求必须加这行代码 -->
										    <div class="form-group">
											<label for="exampleInputName2">定时器ID
												<input class="form-control" name="timeIdVO" placeholder="TimerID" type="text" value="${timerListConditionVO.timeIdVO!}" style="width:120px">
											</label>
											<label for="exampleInputName" style="margin-left: 30px;">任务批次号
												<input class="form-control" name="taskIdVO" placeholder="任务批次号" type="text" value="${timerListConditionVO.taskIdVO!}" style="width:110px">
											</label>
											<label for="exampleInputName" style="margin-left: 30px;">定时器编码
												<input class="form-control" name="timerCodeVO" placeholder="定时器编码" type="text" value="${timerListConditionVO.timerCodeVO!}" style="width:110px">
											</label>
											<label for="exampleInputName" style="margin-left: 30px;">定时器状态
												<select name="timerStatus" id="timerStatus"  value="${timerListConditionVO.timerStatus!}"  class="form-control"  style="width:110px;height: 35px">
                                                          <#list timerStatusTypeList as timerStatusType>
													    <option  value="${timerStatusType.value}" >${timerStatusType.showName}</option>
													</#list>
												</select>
											</label>
											<button type="submit" class="btn btn-pink btn-sm" id="search">
												<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
												查询
											</button>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- 筛选条件结束 -->
				<!-- tab开始 -->
				<div class="row">
					 <div class="col-sm-12">
						<div class=" widget-box" style="border:none;">
									<table id="dynamic-table" 
									class="table table-striped table-bordered table-hover dataTable no-footer" 
									role="grid" aria-describedby="dynamic-table_info">
										<thead>
											<tr>
												<th>TimerID</th>
												<th>任务编码</th>
												<th>任务批次号</th>
												<th>定时器编码</th>
												<th>定时器名称</th>
											<!-- 	<th>执行方式</th> -->
											    <th>定时器参数</th>
												<th>定时器周期</th>
												<th>配置是否有效</th>
											<!-- 	<th>状态</th> -->
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
										      	<#if timerVOList?? && timerVOList?size&gt;0> 
										      	<#list  timerVOList as timerVO>
												<tr class="">
												    <td>${timerVO.timer_id!}</td>
												    <td>${timerVO.job_code!}</td>
													<td>${timerVO.task_id!}</td>
													<td>${timerVO.timer_code!}</td>
												    <td>${timerVO.timer_name!}</td>
										<!-- 			<td>
													<#if timerVO.exec_mode == "0">
													 周期执行
													<#else>
													非周期执行
													</#if> 
													</td> -->
												    <td>${timerVO.timer_param!}</td>
													<td>${timerVO.timer_cron!}</td>
												     <td>
												    <#if timerVO.timer_valid == 1>
												                        有效 
												    <#else>
												                        无效 
												    </#if>                                        
												    </td>
												<!--     <td>
												    <#list timerStatusTypeList as timerStatusType>
                                                        <#if timerVO.timer_status ==timerStatusType.value >
															${timerStatusType.showName!}
														</#if>	
						                            </#list>
												    </td> -->
													<td  >
													<div class="hidden-sm hidden-xs action-buttons" align="right">
														<a class="green" onclick="updateTimer('${timerVO.timer_id!}')"
														role="button"> 
														   <i class="ace-icon fa fa-pencil bigger-130"></i>
													    </a>
													    <a title="刷新" class="green"  onclick="refreshTimer('${timerVO.timer_id!}')" role="button"  data-toggle="modal">
															<i class="ace-icon fa fa-refresh bigger-120"></i>
										                </a>
													    <#if timerVO.timer_status=="0"> 
														<a title="立即执行" class="green" onclick="fireTimer('${timerVO.timer_id!}')" role="button"  data-toggle="modal">
															<i class="ace-icon fa fa-check bigger-120"></i>
										                </a>
										                </#if>
													</div>
												    </td>
												</tr>
									    </#list> <#else>
										<tr>
											<td colspan="12">
												<div class="alert alert-danger" style="margin-bottom: 0px;"
													role="alert">没有记录!</div>
											</td>
										</tr>
										</#if>
									</tbody>
								</table>
                                <#include "/paginator.html">
                          </div>
						</div>
					</div>
					<!-- tab结束-->
				</div>
				<div class="row">
					<div class="col-xs-12">
						<button class="btn btn-info" data-toggle="modal" type="button"
							style="display: none;" id="update" data-target="#myModal">
						</button>
						<form id="updateCode" class="form-horizontal" role="form"
							action="${request.contextPath}/backJobConfig/timerUpdate">
							<input type="hidden" id="_csrf" name="${_csrf.parameterName}"
											value="${_csrf.token}" />
							<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
								aria-labelledby="myModalLabel" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal"
												aria-hidden="true">×</button>
											<h4 class="modal-title" id="myModalLabel">Timer配置</h4>
										</div>
										<div class="modal-body">
											<input id="timer_id" name="timer_id" value="" type="hidden">

											<div class="space-4"></div>
											<div class="form-group">
												<div class="col-sm-9">											 
												    <div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 系统代码 </label>

														<div class="col-sm-9">
															<input type="text" id="syscode" name="syscode"
																placeholder="系统代码" class="form-control" readonly>
														</div>
													</div>
												    <div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">任务编码 </label>

														<div class="col-sm-9">
															<input type="text" id="job_code" name="job_code"
																placeholder="任务编码" class="form-control" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">任务批次号 </label>

														<div class="col-sm-9">
															<input type="text" id="task_id" name="task_id"
																placeholder="任务批次号" class="form-control" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">定时器编码 </label>

														<div class="col-sm-9">
															<input type="text" id="timer_code" name="timer_code"
																placeholder="定时器编码" class="form-control" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">定时器名称 </label>

														<div class="col-sm-9">
															<input type="text" id="timer_name" name="timer_name"
																placeholder="定时器名称" class="form-control" readonly>
														</div>
													</div>
													
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">执行方式 </label>

														<div class="col-sm-9">
															<input type="text" id="exec_mode" name="exec_mode"
																placeholder="执行方式" class="form-control" readonly>
														</div>
													</div>
													
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 定时器处理类 </label>

														<div class="col-sm-9">
															<input type="text" id="timer_classname" name="timer_classname"
																placeholder="定时器处理类" class="form-control">
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 定时器参数 </label>

														<div class="col-sm-9">
															<input type="text" id="timer_param" name="timer_param"
																placeholder="定时器参数" class="form-control">
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 定时器周期</label>

														<div class="col-sm-9">
															<input type="text" id="timer_cron" name="timer_cron"
																placeholder="定时器周期" class="form-control">
														</div>
													</div>
									
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">配置是否有效</label>		
														<div class="col-sm-9">
                                                          <select name="timer_valid" id="timer_valid" aria-controls="dynamic-table" class="form-control input-sm">
															    <option  value="0" >无效</option>
															     <option  value="1" >有效</option>
														  </select>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 状态 </label>
														<div class="col-sm-9">	
                                                         <select name="timer_status" id="timer_status" aria-controls="dynamic-table" class="form-control input-sm">
                                                            <#list timerStatusTypeList as timerStatusType>
															    <option  value="${timerStatusType.value}" >${timerStatusType.showName}</option>
															</#list>
														</select>
													</div>
													</div>
												</div>
											</div>
										</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-pink btn-sm"
												data-dismiss="modal">关闭</button>
											<button type="submit" class="btn btn-pink btn-sm" id="save">
												提交</button>
										</div>
									</div>
									<!-- /.modal-content -->
								</div>
								<!-- /.modal -->
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div> 
    <input type="hidden" id="timerlistcontext" value="${request.contextPath}"/>                      
<script type="text/javascript">
var timerlistcontext = $("#timerlistcontext").val();
function updateTimer(timer_id){
	   $.ajax({
			url : timerlistcontext+'/backJobConfig/TimerEdit?timer_id='+timer_id,
			type : "GET",
			success:function(data) {
				console.log(data);
				if(data.sessionStatus==540){//异步请求session过期状态
					window.location.href=timerlistcontext+"/login";
					//location.href="show_product?prodId="+prod_id+"&sceneryName="+tdSceneryName+"&pageNum="+$("#pageNum").val();
				}else if(data.code=1){
					var timerVO = data.timerVO;
					$("#myModal").modal("show");
					$('#timer_classname').val(timerVO.timer_classname);
					$('#timer_param').val(timerVO.timer_param);
					$('#timer_cron').val(timerVO.timer_cron);
					$('#timer_valid').find("option[value="+timerVO.timer_valid+"]").attr("selected",true);
					$('#timer_status').find("option[value="+timerVO.timer_status+"]").attr("selected",true);
					$("#syscode").val(timerVO.syscode);
					$("#job_code").val(timerVO.job_code);
					$("#task_id").val(timerVO.task_id);
					$("#timer_code").val(timerVO.timer_code);
					$("#timer_name").val(timerVO.timer_name);
					var exec_mode = "";
					if(timerVO.task_id==1){
						exec_mode = "非周期执行";
					}else if(timerVO.task_id==0){
						exec_mode = "周期执行";
					}
					$("#exec_mode").val(exec_mode);
					
					$('#timer_id').val(timerVO.timer_id);
				}
			}
		  }); 
	 
	  
};

function refreshTimer(timer_id){
	   $.ajax({
			url : timerlistcontext+'/backJobConfig/TimerRefresh?timer_id='+timer_id,
			type : "GET",
			success:function(data) {
				if(data.sessionStatus==540){//异步请求session过期状态
					window.location.href=timerlistcontext+"/login";
					//location.href="show_product?prodId="+prod_id+"&sceneryName="+tdSceneryName+"&pageNum="+$("#pageNum").val();
				}else if(data.code==0)
				{
					showMsg("刷新定时任务完成！");
				}
				else
				{
					showMsg("刷新定时任务失败！");
				}
				
			},
			error:function(data) {
				showMsg("刷新定时任务异常！");
			}
		  }); 
	 
	  
};
function fireTimer(timer_id){
	 $.ajax({
			url : timerlistcontext+'/backJobConfig/TimerFire?timer_id='+timer_id,
			type : "GET",
			success:function(data) {
				if(data.sessionStatus==540){//异步请求session过期状态
					window.location.href=timerlistcontext+"/login";
				}else if(data.code==0)
				{
					showMsg("立即执行定时任务完成！");
				}
				else
				{
					showMsg("立即执行定时任务失败！");
				}
				
			},
			error:function(data) {
				showMsg("立即执行定时任务异常！");
			}
		  }); 
	 
	  
}
</script>
<script type="text/javascript">
/**
 * 翻页到指定页数
 */
var showPage = function(page,obj) {
	var objId = $(obj).attr("id");//当前按钮的id
	var pages = $("#sp_1_grid-pager").html();//总页数
	var pageNum = $(".ui-pg-input").val();//当前页
	if(pageNum == pages){
		if(objId == "next_grid-pager" || objId == "last_grid-pager"){
			return;
		}
	}else if(pageNum == 1){
		if(objId == "prev_grid-pager" || objId == "first_grid-pager"){
			return;
		}
	} 
	$("td").attr("onclick","");
	var action = $("#searchForm").attr("action");
	action = action + "?page=" + page;
	$("#searchForm").attr("action", action);
	$("#searchForm").submit();
}

$(".ui-pg-input").blur(function(){
	var objValue = $(".ui-pg-input").val();//文本框输入页数
	var pages = $("#sp_1_grid-pager").html();//总页数
	if(Number(objValue) > pages || Number(objValue) < 1){
		return;
	}
	$("td").attr("onclick","");
	var action = $("#searchForm").attr("action");
	action = action + "?page=" + objValue;
	$("#searchForm").attr("action", action);
	$("#searchForm").submit();
});
</script>
	<script src="${request.contextPath}/static/assets/js/bootstrap.min.js"></script>
	<!-- page specific plugin scripts -->
	<script type="text/javascript" src="${request.contextPath}/static/javascripts/moment.js"></script>
	<script type="text/javascript" src="${request.contextPath}/static/javascripts/daterangepicker.js"></script>
	<!-- ace scripts -->
	<script src="${request.contextPath}/static/assets/js/jquery.gritter.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/ace-elements.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/ace.min.js"></script>
	<!-- user scripts -->
	<script src="${request.contextPath}/static/assets/js/user/base.js"></script>
	<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bsie-paginator.css" />
</body>
</html>